package com.cloud.edm.warningEvent.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.edm.warningEvent.domain.Event;
import com.cloud.edm.warningEvent.repository.EventRepository;

/**
 * 作用： ① 测试服务实例的相关内容 ② 为后来的服务做提供
 * 
 * @author xiaomayi
 */
@RestController
public class EventController {
	@Autowired
	private DiscoveryClient discoveryClient;
	@Autowired
	private EventRepository eventRepository;

	/**
	 * 注：@GetMapping("/{id}")是spring 4.3的新注解等价于：
	 * 
	 * @RequestMapping(value = "/id", method = RequestMethod.GET)
	 *                       类似的注解还有@PostMapping等等
	 * @param id
	 * @return user信息
	 */
	@GetMapping("/{id}")
	public Event findById(@PathVariable Long id) {
		// Optional<Event> findOne = this.eventRepository.findById(arg0)(id);
		// findOne
		// return findOne;

		Event event = new Event();
		event.setId(1L);

		return event;
	}

	/**
	 * 本地服务实例的信息
	 * 
	 * @return
	 */
	@GetMapping("/instance-info")
	public List<String> showInfo() {
		// discoveryClient.getServices()
		// ServiceInstance localServiceInstance =
		// this.discoveryClient.getLocalServiceInstance();
		// return localServiceInstance;

		return discoveryClient.getServices();
	}
}
